package com.example.json_parse;

import java.io.*;

import android.os.Bundle;
import android.app.Activity;
import android.text.method.ScrollingMovementMethod;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {
	private TextView json;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		json = (TextView)findViewById(R.id.myjson);
		String str = getFileContent();
		json.setText(str);
		json.setMovementMethod(ScrollingMovementMethod.getInstance());
	}
	
	private String getFileContent() {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		BufferedReader br = null;
		try{
			br = new BufferedReader (new InputStreamReader(getResources().openRawResource(R.raw.myjson)));
			String stri = br. readLine();
			while(stri != null){
				sb.append(stri+"\n");
				stri = br.readLine();
			}
		}catch(Exception ex){
			System.out.println("EX"+ex);
		}finally{
			if(br != null){
				try {
					br.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		//InputStream is = getResources().openRawResource(R.raw.myjson);
		return sb.toString();
		//return null;
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
